package qianting.news.common.inteceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import qianting.news.common.utils.AppThreadLocalUtil;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Component
@ConditionalOnMissingClass("org.springframework.cloud.gateway.filter.GlobalFilter")
public class MyFeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        Long id = AppThreadLocalUtil.getUser().getId();
        template.header("userId", id+"");
    }
}
